home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWDebug / Sources / FWPrfCnt.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  3.1 KB  |  119 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPrfCnt.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWSTDDEF_H
  13. #include "FWStdDef.h"
  14. #endif
  15.  
  16. #ifdef FW_PROFILE
  17.  
  18. #ifndef FWPRFCNT_H
  19. #include "FWPrfCnt.h"
  20. #endif
  21.  
  22. #include <string.h>
  23.  
  24. #pragma segment FWDebug_PerformanceCounter
  25.  
  26. #if FW_LIB_EXPORT_PRAGMAS
  27. #pragma lib_export on
  28. #endif
  29.  
  30. //========================================================================================
  31. // CLASS FW_CPerformanceCounter
  32. //========================================================================================
  33.  
  34. #ifdef FW_BUILD_WIN
  35. DWORD FW_CPerformanceCounter::gWinOverhead = (DWORD) -1;
  36. DWORD FW_CPerformanceCounter::gWinFreq = 0;
  37. #endif
  38.  
  39. #ifdef FW_BUILD_MAC
  40. const long kMacMaxInterval    = -60l * 1000l * 1000l;    // microseconds: 1 minute
  41.  
  42. long FW_CPerformanceCounter::gMacTMOverhead = -1;
  43. #endif
  44.  
  45. //----------------------------------------------------------------------------------------
  46. // FW_CPerformanceCounter::FW_CPerformanceCounter
  47. //----------------------------------------------------------------------------------------
  48.  
  49. FW_CPerformanceCounter::FW_CPerformanceCounter() :
  50.     fResult(-1)
  51. {
  52. #ifdef FW_BUILD_WIN
  53.     ::QueryPerformanceCounter(&fWinBegin);
  54.     
  55.     // Determine the overhead
  56.     if (gWinOverhead == (DWORD) -1)
  57.     {
  58.         ::QueryPerformanceCounter(&fWinEnd);
  59.         gWinOverhead = fWinEnd.LowPart - fWinBegin.LowPart;
  60.         
  61.         // Get the resolution
  62.         LARGE_INTEGER liFreq;
  63.         ::QueryPerformanceFrequency(&liFreq);
  64.         gWinFreq = liFreq.LowPart;
  65.  
  66.         ::QueryPerformanceCounter(&fWinBegin);
  67.     }
  68. #endif
  69. #ifdef FW_BUILD_MAC
  70.     ::memset(&fMacTMTask, 0, sizeof(fMacTMTask));
  71.     ::InsTime((QElemPtr) &fMacTMTask);
  72.     ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
  73.     
  74.     // Determine the overhead
  75.     if (gMacTMOverhead == -1)
  76.     {
  77.         ::RmvTime((QElemPtr) &fMacTMTask);
  78.         gMacTMOverhead = fMacTMTask.tmCount - kMacMaxInterval;
  79.  
  80.         ::InsTime((QElemPtr) &fMacTMTask);
  81.         ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
  82.     }
  83.  
  84.     fMacIsInQueue = TRUE;
  85. #endif
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // FW_CPerformanceCounter::~FW_CPerformanceCounter
  90. //----------------------------------------------------------------------------------------
  91.  
  92. FW_CPerformanceCounter::~FW_CPerformanceCounter()
  93. {
  94. #ifdef FW_BUILD_MAC
  95.     if (fMacIsInQueue)
  96.         ::RmvTime((QElemPtr) &fMacTMTask);
  97. #endif
  98. }
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // FW_CPerformanceCounter::EndCheckPoint
  102. //----------------------------------------------------------------------------------------
  103.  
  104. void FW_CPerformanceCounter::EndCheckPoint()
  105. {
  106. #ifdef FW_BUILD_WIN
  107.     ::QueryPerformanceCounter(&fWinEnd);
  108.     fResult = fWinEnd.LowPart - fWinBegin.LowPart - gWinOverhead;
  109. #endif
  110. #ifdef FW_BUILD_MAC
  111.     FW_ASSERT(fMacIsInQueue);
  112.     ::RmvTime((QElemPtr) &fMacTMTask);
  113.     fMacIsInQueue = FALSE;
  114.     fResult = fMacTMTask.tmCount - kMacMaxInterval - gMacTMOverhead;
  115. #endif
  116. }
  117.  
  118. #endif
  119.